/******************************************************************************
 *                 Devantech SRF10 Sonar Ranger Functions
 ******************************************************************************/

#ifndef _SONAR_H_
#define _SONAR_H_

#include <util/twi.h>

uint8_t sonarAddrs[5] = {0xE0, 0xE2, 0xE4, 0xE6, 0xE8};

/******************************************************************************
 *  Before reading measurements from sonar you should send command 
 *  sonarStart(address) and wait long enough (>= 65ms) to let sonar 
 *  finish taking measurements. After that you can read last measurement
 *  with sonarRead(address). If it returns -1 than reading was bad and you 
 *  should try again. To take one more measurement you should call 
 *  sonarStart again.
 ******************************************************************************/
 

/******************************************************************************
 *  Returns -1 if no reading is available yet, otherwise returns 
 *  in units given in sonarStart (80 for inches, 81 for centimeters
 ******************************************************************************/
int16_t sonarRead(uint8_t address);

/******************************************************************************
 *  Sends command to sonar to start measuring distance.
 ******************************************************************************/
void sonarStart(uint8_t address);

/******************************************************************************
 *  Changes sonar's given address to the new one
 ******************************************************************************/
void sonarChangeAddress(uint8_t originalAddress, uint8_t newAddress);

#endif
